//
//  ProgressView.m
//  自定义下载进度条
//
//  Created by Jorn.Wu on 15/5/15.
//  Copyright (c) 2015年 Jorn.Wu. All rights reserved.
//

#import "ProgressView.h"

@implementation ProgressView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.progressLayer = [CALayer layer];
        self.progressLayer.frame = CGRectMake(0, 0, 0, frame.size.height);
        self.progressLayer.backgroundColor = [UIColor redColor].CGColor;
        [self.layer addSublayer:self.progressLayer];
        
        self.currentViewWidth = frame.size.width;//存储当前View的宽度值
    }
    return self;
}
#pragma mark - 重写setter 和 getter方法
@synthesize progress = _progress;
- (void)setProgress:(CGFloat)progress{
    _progress = progress;
    if (progress <= 0) {
        self.progressLayer.frame = CGRectMake(0, 0, 0, self.frame.size.height);
    }
    else if (progress <= 1){
        self.progressLayer.frame = CGRectMake(0, 0,
                                              progress * self.currentViewWidth,
                                              self.frame.size.height);
    }
    else
    {
        self.progressLayer.frame = CGRectMake(0, 0, self.currentViewWidth, self.frame.size.height);
    }
}
- (CGFloat)progress{
    return _progress;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
